package utils

import (
	"github.com/garyburd/redigo/redis"
	"time"
)


//redis连接池
var RedisPool *RedisConnPool

type RedisConnPool struct {
	//自带锁
	Pool *redis.Pool
}

func GetRedisConnPool(addressAndPort string, maxIdle, maxActive int, idleTimeOut time.Duration) *RedisConnPool {
	if RedisPool == nil {
		RedisPool = &RedisConnPool{
			Pool: &redis.Pool{
				MaxIdle:     maxIdle,
				MaxActive:   maxActive,
				IdleTimeout: idleTimeOut,
				Dial: func() (redis.Conn, error) {
					return redis.Dial("tcp", addressAndPort)
				},
			},
		}
	}
	return RedisPool
}
